<?php

class MobileModule extends CWebModule
{
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'mobile.models.*',
			'mobile.components.*',
		));
		
		// make the mobile layout
		$this->layoutPath = Yii::getPathOfAlias('mobile.views.layouts');
		$this->layout = 'mobile-layout';
		
		// reset the errorHandler. PS: only this way works.
		$components = array(
			'errorHandler' => array(
					'errorAction' => '/mobile/default/error',
			),
		);
		
		Yii::app()->setComponents($components);
		// add these components to this instance
		$this->setComponents($components);
		
		Yii::app()->setTimeZone('Europe/Helsinki');
		
		$lang = Yii::app()->request->getParam('lang');
		BUtils::SetLanguage($lang);
		
		//cancel the duplicate load js
		Yii::app()->clientScript->scriptMap['jquery.js'] = false;
		Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
		//cancel the duplicate bootstrap
		Yii::app()->clientScript->scriptMap['bootstrap.css'] = false;
		Yii::app()->clientScript->scriptMap['bootstrap.js'] = false;
		Yii::app()->clientScript->scriptMap['bootstrap.min.css'] = false;
		Yii::app()->clientScript->scriptMap['bootstrap.min.js'] = false;
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			// this method is called before any module controller action is performed
			// you may place customized code here
			return true;
		}
		else
			return false;
	}
}
